package org.example.thread;
// JOIN
public class Demo4 {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("t1 开始");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t1 结束");
        });
        Thread t2 = new Thread(() -> {
            System.out.println("t2 开始");
            try {
                // t2 线程会等待 t1 线程执行结束 在继续执行.
                // t2 进入阻塞状态
                t1.join();
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2 结束");
        });

        t1.start();
        t2.start();
    }


}
